package per.mnxc;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

/**
 * @BelongsProject: spring_stu
 * @BelongsPackage: per.mnxc
 * @Author: mnxc
 * @Description: 快速生成springboot+mybatis_plus框架
 * @Version: 1.0
 */
public class Generator {
    public static void main(String[] args) {
        AutoGenerator autoGenerator = new AutoGenerator();

        DataSourceConfig datasource = new DataSourceConfig();
        datasource.setDriverName("com.mysql.cj.jdbc.Driver");
        datasource.setUrl("jdbc:mysql://localhost:3306/cul_plants_db?serverTimezone=UTC");
        datasource.setUsername("root");
        datasource.setPassword("jadmin");
        autoGenerator.setDataSource(datasource);

        //设置全局配置
        GlobalConfig globalConfig = new GlobalConfig();
        globalConfig.setOutputDir("D:\\IdeaProjects\\javawebtest\\spring_stu\\flower"+ "/src/main/java");
        globalConfig.setOpen(false);
        globalConfig.setAuthor("mnxc");
        globalConfig.setFileOverride(true);
        globalConfig.setMapperName("%sMapper");
        globalConfig.setIdType(IdType.ASSIGN_ID);
        autoGenerator.setGlobalConfig(globalConfig);

        //设置包名相关配置
        PackageConfig packageInfo = new PackageConfig();
        packageInfo.setParent("per.mnxc");
        packageInfo.setEntity("pojo");
        packageInfo.setMapper("mapper");
        autoGenerator.setPackageInfo(packageInfo);

        //策略设置
        StrategyConfig strategyConfig = new StrategyConfig();
        // strategyConfig.setInclude(""); //设置当前参与生成的表名
        strategyConfig.setTablePrefix("tbl_"); //设置数据库表名前缀
        strategyConfig.setNaming(NamingStrategy.underline_to_camel);
        strategyConfig.setRestControllerStyle(true);
        strategyConfig.setLogicDeleteFieldName("deleted");
        strategyConfig.setVersionFieldName("version");
        strategyConfig.setEntityLombokModel(true);
        autoGenerator.setStrategy(strategyConfig);

        //执行
        autoGenerator.execute();
    }
}
